package com.blog.controller;
import com.blog.exception.ExceptionEnum;
import com.blog.pojo.ResultResponse;
import com.blog.pojo.Tag;
import com.blog.service.HobbyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/hobbies")
@RestController
public class HobbyController {

    @Autowired
    private HobbyService hobbyService;

    // 查看当前登录用户感兴趣的标签
    @GetMapping("/currentUser")
    public ResultResponse listByCurrentUser() {
        log.info("查看当前用户兴趣");
        List<Tag> tagList = hobbyService.listByCurrentUser();
        return ResultResponse.success(tagList);
    }

    // 根据用户id查看用户感兴趣的标签
    @GetMapping("/{id}")
    public ResultResponse listByUserId(@PathVariable Integer id) {
        log.info("查看用户兴趣，用户id: {}", id);
        List<Tag> tagList = hobbyService.listByUserId(id);
        return  ResultResponse.success(tagList);
    }

    // 当前用户添加感兴趣的标签
    @PostMapping
    public ResultResponse add(@RequestParam List<Integer> tagIds) {
        log.info("当前用户添加兴趣标签，标签id: {}", tagIds);
        if(tagIds == null) {
            return ResultResponse.error(ExceptionEnum.EMPTY_TAG);
        }
        hobbyService.add(tagIds);
        return ResultResponse.success();
    }

    // 当前用户删除感兴趣的标签
    @DeleteMapping("/delete/{tagId}")
    public ResultResponse delete(@PathVariable Integer tagId) {
        log.info("当前用户删除兴趣标签，标签id:{}", tagId);
        hobbyService.delete(tagId);
        return ResultResponse.success();
    }

}
